package com.qingshu.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qingshu.common.entity.custom.Lyric;
import com.qingshu.common.util.model.FieldUtil;
import com.qingshu.mapper.LyricMapper;
import com.qingshu.service.ILyricService;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Huzz
 * @since 2021-12-09
 */
@Service
public class LyricServiceImpl extends ServiceImpl<LyricMapper, Lyric> implements ILyricService {

    @Override
    public boolean addLyric(Lyric lyric) {
        FieldUtil.setCreatedAndUpdateField(lyric);
        return this.baseMapper.insert(lyric) > 0;
    }

    @Override
    public boolean updateLyricById(Lyric lyric) {
        FieldUtil.setUpdateField(lyric);
        return this.baseMapper.updateById(lyric) > 0;
    }

    @Override
    public boolean delLyricById(Integer lyricId) {
        // 歌词规定只能逻辑删除, 删除后歌曲管理中不应该让其继续调用
        return this.baseMapper.removeById(lyricId);
    }

    @Override
    public String findLyricPage(Integer pageNum, Integer pageSize, Lyric model) {
        // TODO 歌词查询list
        return null;
    }

    @Override
    public Lyric finLyricById(Integer lyricId) {
        return this.baseMapper.selectById(lyricId);
    }

    @Override
    public Lyric finUserByRoleName(String lyricName) {
        LambdaQueryWrapper<Lyric> wrapper = new LambdaQueryWrapper<>();
        wrapper.like(Lyric::getLyricName, lyricName);
        return this.baseMapper.selectOne(wrapper);
    }
}
